/*
 * GoogleReaderHistoryXMLReader.java
 *
 * Created on April 29, 2007, 7:30 PM
 *
 *  APPLICATION NAME
    Copyright (C) 2007  Anand Kishore (anand@semanticvoid.com)
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

package com.semanticvoid.lifelogger.xml.parser;

import com.semanticvoid.lifelogger.entity.TaggedBrowseHistoryEntity;
import com.semanticvoid.lifelogger.xml.parser.interfaces.IReturnsTaggedBrowseObjects;
import com.semanticvoid.lifelogger.utils.DOMHelper;
import java.util.Vector;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * This is a subclass of the XMLReader which is used for parsing the Google Reader
 * xml file. It implements the following interface - IReturnsTaggedBrowseObjects. Hence
 * it can be used to return TaggedBrowseHistoryEntity objects which are essentially
 * BrowseHistoryEntity objects with tags.
 * @author anand kishore
 */
public class GoogleReaderHistoryXMLReader extends XMLReader implements IReturnsTaggedBrowseObjects {
    
    /**
     * Creates a new instance of GoogleReaderHistoryXMLReader
     * @param path the path of the xml file
     */
    public GoogleReaderHistoryXMLReader(String path) {
        super(path);
    }
    
    /**
     * Get the vector of the TaggedBrowseHistoryEntity (Google Reader read posts) from
     * the xml document
     * @return the vector of TaggedBrowseHistoryEntity objects
     */
    public Vector<TaggedBrowseHistoryEntity> getTaggedObjects() {
        Vector<TaggedBrowseHistoryEntity> entities = new Vector<TaggedBrowseHistoryEntity>();
        
        for(String path : xmlFilePaths) {
            Document xmlDoc = formDocument(path);
            
            if(xmlDoc != null) {
                NodeList nodeList = xmlDoc.getElementsByTagName("entry");

                if(nodeList != null) {
                    for(int index=0; index<nodeList.getLength(); index++) {
                        Node item = nodeList.item(index);

                        TaggedBrowseHistoryEntity tbe = DOMHelper.formReadBlogEntity(item);
                        
                        if(tbe != null) {
                            entities.add(tbe);
                        }
                    }
                }
            }
        }
        
        return entities;
    }
}
